package com.online.edu.service.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.online.edu.common.vo.R;
import com.online.edu.service.pojo.EduTeacher;
import com.online.edu.service.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author 佘莉
 * @since 2020-07-15
 */
@RestController
@RequestMapping("teacher")
public class EduTeacherController {
    @Autowired
    private EduTeacherService eduTeacherService;

    @GetMapping("allTeacher")
    public ResponseEntity<List<EduTeacher>> allTeacher(){
        List<EduTeacher> list = eduTeacherService.list(null);
        if (list == null) {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
        return ResponseEntity.ok(list);
    }
    @GetMapping("delTeacher/{id}")
    public R delTeacher(@PathVariable("id")String   id){
        boolean bool = eduTeacherService.removeById(id);

        return  R.ok().data("bool",bool);
    }
    // 3 分也查询
    @GetMapping("pageList/{page}/{limit}")
    public R getPageTeacher(
            @PathVariable("page")Long  page,
            @PathVariable("limit")Long  limit){

        // 分页
        Page<EduTeacher> pageTeacher = new Page(page,limit);
         eduTeacherService.page(pageTeacher, null);


        return R.ok().data("total", pageTeacher.getTotal()).data("items",pageTeacher.getRecords());
    }

    @GetMapping("pageList/{page}/{limit}/{name}")
    public R getMoreCondtionPageList(
            @PathVariable("page")Long  page,
            @PathVariable("limit")Long  limit,
            @PathVariable("name")String  name){
        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();

        // 分页
        Page<EduTeacher> pageTeacher = new Page(page,limit);
        eduTeacherService.page(pageTeacher, null);


        return R.ok().data("total", pageTeacher.getTotal()).data("items",pageTeacher.getRecords());
    }

}

